package edu.pku.sei.transformation.editor.controller.commands.link;

import org.eclipse.gef.commands.Command;

import edu.pku.sei.transformation.editor.model.Rule;
import edu.pku.sei.transformation.editor.model.RuleInvoke;

public class RuleInvokeDeleteCommand extends Command {
	private Rule caller;
	private Rule callee;
	private RuleInvoke invoke;

	public RuleInvokeDeleteCommand(RuleInvoke invoke) {
		this.invoke = invoke;
		this.caller = invoke.getCaller();
		this.callee = invoke.getCallee();
	}

	@Override
	public boolean canExecute() {
		if (caller != null && callee != null && invoke != null) {
			return true;
		} else {
			return false;
		}
	}

	@Override
	public void execute() {
		this.caller.getInvoke().remove(invoke);
	}

	@Override
	public void undo() {
		this.caller.getInvoke().add(invoke);
		invoke.setCaller(this.caller);
		invoke.setCallee(this.callee);
	}
}
